import React, { memo, useState, useContext, useMemo } from 'react';
import { ChatContentContext } from '@/pages/chat';
import { Spin, Tag } from 'antd';

const GuessQuestions:React.FC<{ defaultQuestions: Record< any> }> = ({ defaultQuestions }) => {
    const { appInfo, handleChat, scrollRef, temperatureValue, resourceValue, currentDialogue } = useContext(ChatContentContext);

    const paramKey: string[] = useMemo(() => {
        return appInfo.param_need?.map(i => i.type) || [];
    }, [appInfo.param_need]);

    return (
        <div className="mt-3">
            <div>
                <span>推荐问题：</span>
                {defaultQuestions.map((item, index) => (
                    <Tag
                        key={item}                    
                        className='p-1 px-2 cursor-pointer'
                            onClick={async () => {
                                handleChat(item || '', {
                                    app_code: appInfo.app_code,
                                    ...(paramKey.includes('temperature') && { temperature: temperatureValue }),
                                    ...(paramKey.includes('resource') && {
                                        select_param:
                                        typeof resourceValue === 'string'
                                            ? resourceValue
                                            : JSON.stringify(resourceValue) || currentDialogue.select_param,
                                    }),
                                });
                                setTimeout(() => {
                                    scrollRef.current?.scrollTo({
                                        top: scrollRef.current?.scrollHeight,
                                        behavior: 'smooth',
                                    });
                                }, 0);
                            }}
                        >
                        {item}
                    </Tag>
                ))}
            </div>
        </div>
    );
};

export default memo(GuessQuestions);